package net.techfuser.bigscreen.sink;

import com.alibaba.fastjson.JSON;
import net.techfuser.bigscreen.entity.ItemSummary;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisCommand;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisCommandDescription;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisMapper;

/**
 * @Description:
 * @Author 左龙龙
 * @Date 21-4-9
 * @Version 1.0
 **/
public class ItemSummayRedisMapper implements RedisMapper<ItemSummary> {

    @Override
    public RedisCommandDescription getCommandDescription() {
        return new RedisCommandDescription(RedisCommand.HSET, "big_screen_item_summary");
    }

    @Override
    public String getKeyFromData(ItemSummary row) {
        return String.format("%s_%s", row.getItem_code(), row.getBarcode());
    }

    @Override
    public String getValueFromData(ItemSummary row) {
        return JSON.toJSONString(row);
    }
}